/**
 * 权限列表返回数据
 */
interface visualAuthorizationListItemReponse{
    /**
     * 可视化权限名称
     */
    name:string;
    /**
     * 一级权限分类
     */
    authorizationType:string;
    /**
     * 二级权限分类名称
     */
    secAuthorizationType:string;
    /**
     * 二级权限分类标签
     */
    secAuthorizationTypeTag:string;
    /**
     * 权限等级
     */
    level:string;
    /**
     * 标签
     */
    tag:Array<string>;
    
    /**
     * 二级权限数组
     */
    secAuthTypeList?:any[]
}
/**获取二级分类列表 */
interface getSecAuthTypeListItemReponse{
    /**二级权限分类名称 */
    secAuthorizationType:string;
    /**二级权限分类标签 */
    secAuthorizationTypeTag:string;
    
    
}

/**
 * 权限服务
 */
interface IvisualAuthorizationService{
    /**
     * 获取权限列表
     */
    getList(userId:string,userGroupId:string):ng.IHttpPromise<ListResponse<visualAuthorizationListItemReponse>>;
    
    /**
     * 添加权限
     * @param name 可视化权限名称
     * @param authorizationType 一级权限分类
     * @param secAuthorizationType 二级权限分类名称
     * @param secAuthorizationTypeTag 二级权限分类标签
     * @param level 权限等级
     * @param tag 标签
     */
    add(name:string,authorizationType:string,secAuthorizationType:string,secAuthorizationTypeTag:string,level:string,tag:Array<string>):ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑权限
     * @param name 可视化权限名称
     * @param tag 标签
     */
    edit(id:string,name:string,tag:Array<string>):ng.IHttpPromise<BaseResponse>;

    /**
     * 删除权限
     */
    delete(id:string):ng.IHttpPromise<BaseResponse>;
    /**获取二级分类列表 */
    getSecAuthTypeList(authorizationType:string,secAuthorizationType:string,skip:number,count:number):ng.IHttpPromise<ListResponse<getSecAuthTypeListItemReponse>>;
}

class visualAuthorizationService implements IvisualAuthorizationService{
    constructor(private http: ng.IHttpService, private route: routeService) {
    }
    /**
     * 获取权限列表
     */
    getList(userId:string,userGroupId:string,logisticsCompanyId?:string):ng.IHttpPromise<ListResponse<visualAuthorizationListItemReponse>>{
        return this.http<ListResponse<visualAuthorizationListItemReponse>>({
            method:"GET",
            url:this.route.getUrl("visualauthorization/GetAuthTreeList?userId={{userId}}&userGroupId={{userGroupId}}&logisticsCompanyId={{logisticsCompanyId}}",{
                userId:userId,
                userGroupId:userGroupId,
                logisticsCompanyId:logisticsCompanyId
            })
        })
    }

    /**
     * 添加权限
     */
    add(name:string,authorizationType:string,secAuthorizationType:string,secAuthorizationTypeTag:string,level:string,tag:Array<string>):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"POST",
            url:this.route.getUrl("visualauthorization",{
            }),
            data:{
                name:name,
                authorizationType:authorizationType,
                secAuthorizationType:secAuthorizationType,
                secAuthorizationTypeTag:secAuthorizationTypeTag,
                level:level,
                tag:tag
            }
        })
    }

    /**
     * 编辑权限
     */
    edit(id:string,name:string,tag:Array<string>):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"PUT",
            url:this.route.getUrl("visualauthorization/{{id}}",{
                id:id
            }),
            data:{
                name:name,
                tag:tag
            }
        })
    }

    /**
     * 删除权限
     */
    delete(id:string):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"DELETE",
            url:this.route.getUrl("visualauthorization/{{id}}",{
                id:id
            })
        })
    }
    /**获取二级分类列表 */
    getSecAuthTypeList(authorizationType:string,secAuthorizationType:string,skip:number,count:number):ng.IHttpPromise<ListResponse<getSecAuthTypeListItemReponse>>{
        return this.http<ListResponse<getSecAuthTypeListItemReponse>>({
            method:"GET",
            url:this.route.getUrl("visualauthorization/getSecAuthTypeList?authorizationType={{authorizationType}}&secAuthorizationType={{secAuthorizationType}}&skip={{skip}}&count={{count}}",{
                authorizationType:authorizationType,
                secAuthorizationType:secAuthorizationType,
                skip:skip,
                count:count
            })
        })
    }

}

angular.module("visualAuthorizationService",[]).service("visualAuthorizationService",['$http','routeService',visualAuthorizationService]);